Ext.onReady(function() {


    // 获取车辆列表
    var carList_store = new Ext.data.Store({
        storeId: 'store3',
        proxy: new Ext.data.HttpProxy({
            url: 'Get_Car_List.action'
        }),
        reader: new Ext.data.JsonReader({
            fields: [{
                    name: 'name'
                }, {
                    name: 'value'
                }]
        })
    });

    carList_store.load();

    var card = new Ext.FormPanel({
        id: 'card',
        name: 'card',
        labelWidth: 80,
        width: '100%',
        height: '100%',
        bodyStyle: 'padding: 4px',
        border: false,
        autoscroll: true,
        frame: true,
        autoScroll: true,
        items: [{
                layout: 'column',
                items: [{
                        columnWidth: .5,
                        layout: 'form',
                        items: [{
                                xtype: "textfield",
                                fieldLabel: "油卡编号",
                                emptyText: '油卡编号(必填)',
                                disabled: false,
                                allowBlank: false,
                                id: 'card_code',
                                name: 'card_code',
                                anchor: "95%"
                            }]
                    }, {
                        columnWidth: .5,
                        layout: 'form',
                        items: [{
                                xtype: 'combo',
                                fieldLabel: '车牌号码',
                                name: 'car_code',
                                displayField: 'name',
                                valueField: 'name',
                                emptyText: '车牌号码',
                                anchor: '95%',
                                typeAhead: true,
                                triggerAction: 'all',
                                queryParam: 'name', autoSelect: false,  triggerAction : 'all', store: carList_store
                            }]
                    }]
            }, {
                xtype: "htmleditor",
                fieldLabel: 'Biography',
                fieldLabel : "备注",
                        emptyText: '备注',
                disabled: false,
                allowBlank: false,
                id: 'remark',
                name: 'remark',
                anchor: "98%"
            }]
    });

    var card_win = new Ext.Window({
        id: 'card_win',
        title: "添加油卡记录",
        border: false,
        bodyBorder: false,
        // layout:'fit',
        width: 630,
        closeAction: 'hide',
        modal: true,
        tbar: ['-', {
                text: ' 提交并继续',
                handler: function() {
                    onSubmit();
                }
            }, '-', {
                text: ' 重置',
                handler: function() {
                    card.getForm().reset();
                }
            }, '-'],
        items: [card]
    });


    function onSubmit() {
        // 提交表单
        if (card.getForm().isValid()) {
            var submitValues = card.getForm().getValues();
            for (var param in submitValues) {
                if (card.form.findField(param)
                        && card.form.findField(param).emptyText == submitValues[param]) {
                    card.form.findField(param).setValue(' ');
                }
            }
            card.getForm().submit({
                url: 'CardAction.action',
                waitMsg: '数据保存中...',
                submitEmptyText: false,
                success: function(c, d) {
                    Ext.MessageBox.alert("操作信息", "成功信息保存！");
                    card.getForm().reset();
                },
                failure: function(c, d) {
                    Ext.MessageBox.show({
                        title: "操作信息",
                        msg: "信息保存出错，请联系管理员！",
                        buttons: Ext.MessageBox.OK,
                        icon: "ext-mb-error"
                    });

                }
            });

        }

    }


    card_win.show();
});
